// pages/evaluate/evaluate.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    star: 5,
    desc: '',
    content: '',
    imgs: []
  },

  evaAdd() {
    let content = this.data.content
    let imgs = this.imgChoose.data.imgs
    let images = ''
    for (let x in imgs) {
      images += images == '' ? imgs[x] : `,${imgs[x]}`
    }
    let goodsId = ''
    let desc = this.data.desc
    for (let x in desc.ordersItemsList) {
      goodsId += goodsId == '' ? desc.ordersItemsList[x] : `,${desc.ordersItemsList[x]}`
    }
    if (content == '') {
      wx.showToast({
        title: '请输入内容',
        icon: 'none'
      })
      return
    }
    wx.$https('goods.eva.add', {
      content: content,
      goodsId: goodsId,
      images: images,
      star: this.data.star,
      ordersId: desc.ordersId
    }).then((res) => {
      wx.showToast({
        title: '评价成功',
        mask: true
      })
      setTimeout(() => {
        wx.navigateBack()
      }, 500)
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // wx.$getPrev(this, {
    //   desc: 'desc'
    // })
    this.setData({
      ordersId: options.ordersId
    })
    this.getDesc()
  },

  getDesc() {
    wx.$https('orders.desc', {
      ordersId: this.data.ordersId
    }).then(res => {
      this.setData({
        desc: res
      })
    })
  },

  contentInp(e) {
    this.setData({
      content: e.detail.value
    })
  },

  starChange: function (e) {
    let that = this
    let star = e.currentTarget.dataset.star
    that.setData({
      star: star
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.imgChoose = this.selectComponent('#imgChoose')
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})